package com.study.rabbitmq.controller;

import com.study.rabbitmq.mqtt2.IotMqttGateway;
import com.study.rabbitmq.mqtt.MqttGateway;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/rabbit")
public class RabbitMsgProdController {

    @Resource
    private IotMqttGateway iotMqttGateway;

    @Resource
    private MqttGateway mqttGateway;


    /**
     * 发送默认主题消息
     * http://localhost:8315/study-rabbitmq/rabbit/sendDefaultTopicMsg?msg=hello,lileixx2
     * @param msg
     * @return
     */
    @GetMapping("/sendDefaultTopicMsg")
    public String sendDefaultTopicMsg(String msg) {
        log.info("sendDefaultTopicMsg: {}", msg);
        iotMqttGateway.sendMessage2Mqtt(msg);
        mqttGateway.sendToMqtt(msg);
        return "success";
    }
}
